﻿using B.Z.BasicData.Domain.Entity.Authorize;
using B.Z.BasicData.ErrorCode;
using B.Z.BasicData.Infrastructure;
using MediatR;
using Microsoft.EntityFrameworkCore;

namespace B.Z.BasicData.API.Read.Application.User
{
    public class CountryQueryCommandHandler : IRequestHandler<CountryQueryCommand, APIResult<List<T_Contry>>>
    {
        private readonly IBaseRepository<T_Contry> contryRepository;

        public CountryQueryCommandHandler(IBaseRepository<T_Contry> contryRepository)
        {
            this.contryRepository = contryRepository;
        }

        public Task<APIResult<List<T_Contry>>> Handle(CountryQueryCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<T_Contry>> result = new APIResult<List<T_Contry>>();
            result.Code = APIEnum.ok;
            result.Message = "获取成功";

            var list = contryRepository.GetAll().AsNoTracking().Where(p => !p.IsDelete && p.T_CityId == request.CityId);
            result.Data = list.ToList();
            return Task.FromResult(result);
        }
    }
}
